<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<%@ page import="projects.task" %>
<%@ page import="userInteraction.readUserInformation" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="createTask" class="projects.task"></jsp:useBean>
<jsp:setProperty property="*" name="createTask"/>
<jsp:useBean id="user" class="userInteraction.readUserInformation"></jsp:useBean>
<jsp:setProperty property="*" name="user"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>

<%
if (request.getParameter("hMilestoneId") == null){
	response.sendRedirect("../General Info/dashboard.jsp");
	}
else  if (session.getAttribute("loggedIn") == null) {
	response.sendRedirect("../User/index.jsp");
	}
else{
%>

<body>
<%
	readUserInformation userInfo = new readUserInformation();
	Integer userId = userInfo.readUserId(session.getAttribute("loggedIn").toString());
	task tsk = new task();
	tsk.setMilestoneId(Integer.parseInt(request.getParameter("hMilestoneId")));
	tsk.setTaskName(request.getParameter("taskName"));
	tsk.setTaskDescription(request.getParameter("taskDesc"));
	tsk.setStartDate(request.getParameter("startDate"));
	tsk.setEndDate(request.getParameter("endDate"));
	tsk.setTaskTypeId(Integer.parseInt(request.getParameter("taskType")));
	tsk.setTaskPriorityId(Integer.parseInt(request.getParameter("taskPriority")));
	tsk.setTaskEffort(Double.parseDouble(request.getParameter("taskEffort")));
	tsk.setStatusId(Integer.parseInt(request.getParameter("taskStatus")));
	tsk.setResolutionId(Integer.parseInt(request.getParameter("taskResolution")));
	Integer taskId = tsk.createTask(userId);
	if ( taskId != 0){
		out.println("succes");
		String taskLink = "../Tasks/task.jsp?id=" + taskId;
		session.setAttribute("postback", "true");
		session.setAttribute("createTask", "true");
		response.sendRedirect(taskLink);
	}
	else
	{
		out.println("futere");
		String taskLink = "../Tasks/createNewTask.jsp?id=" + request.getParameter("id");
		session.setAttribute("postback", "true");
		session.setAttribute("createTask", "false");
		response.sendRedirect(taskLink);
	}
}
%>
</body>
</html>